home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- *
- * File: AtomUtils.c - C Source
- *
- * Author: Deric Horn
- *
- * Common Action Atom utility functions
- *
- * History: <1> (12/2/94) Created this file.
- *
- *----------------------------------------------------------------------------*/
-
- #include "AtomUtils.h"
-
-
- // This routine strips the filename and the preceding ':' character from the
- // pathname.
- // Input - pointer to file pathname
- // Output - modifies pointer
- OSErr StripFileName(char *str)
- {
- unsigned char len = str[0];
-
- while ((str[len] != ':') && (len > 0))
- len--;
-
- if (len > 0) {
- str[0] = len - 1; // parse the ":" from the end of the pathname
- return noErr;
- }
- return -1;
- }
-
- long DirIDFromSpecialPath( StringPtr path, short vRefNum )
- {
- StringPtr s = path;
- OSType folderType;
- short foundVrefNum;
- long foundDirID;
- OSErr err;
-
- for ( ; s[0] != '-' ; s++ ) // step over 'spcl'
- ;
-
- strncpy( (char*)&folderType, &(s[1]), 4 );
- err = FindFolder( vRefNum, folderType, false, &foundVrefNum, &foundDirID );
-
- return( foundDirID );
- }
-
- void PathFromSpecialPath( StringPtr pathStorage, StringPtr path )
- {
- StringPtr s = path;
-
- for ( ; *s != ':' ; s++ )
- ;
-
- pathStorage[0] = path[0] - (s-path) +1; // length of rest of string
- BlockMove( s, &(pathStorage[1]) , pathStorage[0] );
- }
-
-
- OSErr MakeFSSpecFromAAPB( FSSpecPtr myFS, StringPtr path, AAPBRecPtr myAAPBPtr )
- {
- long dirID;
- Str63 pathStorage;
-
- if ( path[1] != ':' ) // special directory in Sys Folder
- {
- dirID = DirIDFromSpecialPath( path, myAAPBPtr->targetVRefNum );
- PathFromSpecialPath( pathStorage, path );
- return ( FSMakeFSSpec( myAAPBPtr->targetVRefNum, dirID, pathStorage, myFS ) );
- }
- else
- {
- return ( FSMakeFSSpec( myAAPBPtr->targetVRefNum, 0L, path, myFS ) );
- }
- }
-
- void pStrcpy(unsigned char *dest, unsigned char *src)
- {
- BlockMove(src, dest, (long) *src + 1);
- }